//
//  main.c
//  ShannonFano
//
//  Created by Alessio Scannapieco on 17.11.11.
//  Copyright 2011 SUPSI - Manno. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "node.h"
#include "shannon_fano.h"

int main (int argc, const char * argv[]) {
    // azione da fare
    int chose = -1;

    printf("*********************************\n");
    printf("**   Canonical Shannon Fano    **\n");
    printf("**    Alessio Scannapieco      **\n");
    printf("**     DTI - SUPSI Manno       **\n");
    printf("*********************************\n\n\n");
    
    while (chose != 0) {
        printf("*********************************\n");
        printf("**    1) Pack a file           **\n");
        printf("**                             **\n");
        printf("**    2) Unpack file           **\n");
        printf("**                             **\n");
        printf("**    0) Exit                  **\n");
        printf("*********************************\n");
        
        printf("What you want to do: ");
        scanf(" %d", &chose);
        
        switch (chose) {
            case 0:
                // uscita dal programma                
                exit(EXIT_SUCCESS);
                
                break;
            case 1:
                // codifica
                if (argc >= 2) {
                    shannonFanoCanonicalEncode((char *)argv[1], (char *)argv[2]);
                } else {
                    printf("No file 2pack\n");
                    exit(EXIT_FAILURE);
                }
                
                break;
                
            case 2:
                // decodifica
                if (argc >= 2) {
                   shannonFanoCanonicalDecode((char *)argv[1], (char *)argv[2]);
                } else {
                    printf("No file 2unpack\n");
                    exit(EXIT_FAILURE);
                }
                
                break;
            default:
                break;
        }
    }
    
    return 0;
}